package com.atguigu.crowd.service.impl;

import com.atguigu.crowd.entity.po.MemberPO;
import com.atguigu.crowd.entity.po.MemberPOExample;
import com.atguigu.crowd.mapper.MemberPOMapper;
import com.atguigu.crowd.service.api.MemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * information
 * Created by Administrator on 2020/3/31.
 */
@Service
@Transactional(readOnly = true)
public class MemberServiceImpl implements MemberService {

    @Autowired
    private MemberPOMapper memberPOMapper;

    @Override
    public MemberPO getMemberPOByLoginAcct(String loginacct) {
        //1.创建一个example对象
        MemberPOExample memberPOExample = new MemberPOExample();
        //2.创建criteria对象
        MemberPOExample.Criteria criteria = memberPOExample.createCriteria();
        //3.封装查询调节
        criteria.andLoginacctEqualTo(loginacct);
        //4.执行查询
        List<MemberPO> memberPOS = memberPOMapper.selectByExample(memberPOExample);

        //5.返回结果
        if (memberPOS == null || memberPOS.size() == 0) {

            return null;
        }
        return memberPOS.get(0);
    }

    @Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class, readOnly = false)
    @Override
    public void saveMember(MemberPO memberPO) {
        memberPOMapper.insertSelective(memberPO);
    }
}
